package cn.iocoder.yudao.module.eval.service.filingoccupation;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.eval.controller.admin.filingoccupation.vo.*;
import cn.iocoder.yudao.module.eval.dal.dataobject.filingoccupation.FilingOccupationDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.eval.dal.mysql.filingoccupation.FilingOccupationMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.eval.enums.ErrorCodeConstants.*;

/**
 * 申请开展评价的职业（工种）关联 Service 实现类
 *
 * @author 龙头企业
 */
@Service
@Validated
public class FilingOccupationServiceImpl implements FilingOccupationService {

    @Resource
    private FilingOccupationMapper filingOccupationMapper;

    @Override
    public Long createFilingOccupation(FilingOccupationSaveReqVO createReqVO) {
        // 插入
        FilingOccupationDO filingOccupation = BeanUtils.toBean(createReqVO, FilingOccupationDO.class);
        // 显式设置deleted字段默认值
        filingOccupation.setDeleted(false);
        filingOccupationMapper.insert(filingOccupation);

        // 返回
        return filingOccupation.getId();
    }

    @Override
    public void updateFilingOccupation(FilingOccupationSaveReqVO updateReqVO) {
        // 校验存在
        validateFilingOccupationExists(updateReqVO.getId());
        // 更新
        FilingOccupationDO updateObj = BeanUtils.toBean(updateReqVO, FilingOccupationDO.class);
        filingOccupationMapper.updateById(updateObj);
    }

    @Override
    public void deleteFilingOccupation(Long id) {
        // 校验存在
        validateFilingOccupationExists(id);
        // 删除
        filingOccupationMapper.deleteById(id);
    }

    @Override
        public void deleteFilingOccupationListByIds(List<Long> ids) {
        // 删除
        filingOccupationMapper.deleteByIds(ids);
        }


    private void validateFilingOccupationExists(Long id) {
        if (filingOccupationMapper.selectById(id) == null) {
            throw exception(FILING_OCCUPATION_NOT_EXISTS);
        }
    }

    @Override
    public FilingOccupationDO getFilingOccupation(Long id) {
        return filingOccupationMapper.selectById(id);
    }

    @Override
    public PageResult<FilingOccupationDO> getFilingOccupationPage(FilingOccupationPageReqVO pageReqVO) {
        return filingOccupationMapper.selectPage(pageReqVO);
    }

}